package gitee.derumin.lifeissohard.generate.loot_tables;

import gitee.derumin.lifeissohard.item.LishItems;
import gitee.derumin.lifeissohard.tools.LishIdentifiers;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.SimpleFabricLootTableProvider;
import net.minecraft.item.Items;
import net.minecraft.loot.LootPool;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextTypes;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.function.SetNameLootFunction;
import net.minecraft.loot.provider.number.ConstantLootNumberProvider;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;

import java.util.Optional;
import java.util.function.BiConsumer;

public class Special extends SimpleFabricLootTableProvider {
    public Special(FabricDataOutput output) {
        super(output, LootContextTypes.GENERIC);
    }

    @Override
    public void accept(BiConsumer<Identifier, LootTable.Builder> consumer) {
        consumer.accept(LishIdentifiers.LootTables.IMAGED_CAKE,LootTable.builder()
                .pool(LootPool.builder()
                        .rolls(ConstantLootNumberProvider.create(1))
                        .with(ItemEntry.builder(LishItems.IMAGED_CAKE)
                                .apply(SetNameLootFunction.builder(
                                        Text.selector("@s", Optional.of(Text.literal(",")))
                                                .append(Text.translatable("item.lifeissohard.imaged_cake.reward"))
                                                .setStyle(Style.EMPTY
                                                        .withColor(Formatting.GOLD)
                                                        .withBold(true)
                                                        .withItalic(true)),
                                        LootContext.EntityTarget.THIS)))
                        .build()));
        consumer.accept(LishIdentifiers.LootTables.FIRST_THIRSTY, LootTable.builder()
                .pool(LootPool.builder()
                        .rolls(ConstantLootNumberProvider.create(3))
                        .with(ItemEntry.builder(Items.GLASS_BOTTLE))
                        .build()));
        consumer.accept(LishIdentifiers.LootTables.BLOOD_TESTER, LootTable.builder()
                .pool(LootPool.builder()
                        .rolls(ConstantLootNumberProvider.create(1))
                        .with(ItemEntry.builder(LishItems.BLOOD_TESTER))
                        .build()));
    }
}
